import {
	defineStore
} from 'pinia';


export const useUserStore = defineStore('user', {
	state: () => ({
		access_token: uni.getStorageSync('access_token') ? uni.getStorageSync('access_token') : '',
		UserAccessInfo: uni.getStorageSync('UserAccessInfo') ? uni.getStorageSync('UserAccessInfo') : {},
	}),
	actions: {
		assignUserAccessInfo(UserAccessInfo) {
			this.UserAccessInfo = {
				...this.UserAccessInfo,
				...UserAccessInfo,
			}
			uni.setStorageSync('UserAccessInfo', UserAccessInfo);
		},
		setUserToken(access_token) {
			this.access_token = access_token;
			uni.setStorageSync('access_token', access_token);
		},
		clearUserAccessInfo() {
			this.UserAccessInfo = {};
		},
		clearUserToken() {
			this.access_token = '';
		},
		clearAll() {
			this.clearUserAccessInfo();
			this.clearUserToken();
			uni.clearStorageSync();
		},
	},
});